#include "RenderManager.h"
#include <Irrlicht\irrlicht.h>

using namespace Render;

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

RenderManager::RenderManager() : device(NULL)
{
	device = createDevice( video::EDT_OPENGL, dimension2d<u32>(800,600), 32, false, false, false, 0);
	device->setWindowCaption(L"DEW Client");

	driver = device->getVideoDriver();
	smgr = device->getSceneManager();
	gui = device->getGUIEnvironment();

	ISceneNode *cube = smgr->addCubeSceneNode();
	cube->setMaterialFlag(EMF_LIGHTING, false);
	cube->setPosition(vector3df(0.0f, 0.0f, 100.0f));
	ICameraSceneNode *camera = smgr->addCameraSceneNodeFPS();
}

RenderManager::~RenderManager()
{
	if(device)
	{
		device->drop();
		//delete device;
	}
}

bool RenderManager::update(const unsigned int &pulse_ms)
{
	float dt = (float)pulse_ms / 1000.0f;

	if(!device->run())
		return false;

	if (!device->isWindowActive())
	{
		device->yield();
		return true;
	}

	driver->beginScene(true, true, SColor(255,100,101,140));
	smgr->drawAll();
	gui->drawAll();
	driver->endScene();
	return true;
}
